package cn.com.xy.sms.sdk.ui.popu.widget;

import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.com.xy.sms.sdk.constant.Constant;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.util.JsonUtil;
import cn.com.xy.sms.sdk.util.StringUtils;

@SuppressLint("ResourceAsColor")
public class DuoquBaseHolder {
    public TextView mTitleView;
    public TextView mContentView;
    
    public DuoquBaseHolder() {
    
    }
    
    public void setContent(int pos, BusinessSmsMessage message, String dataKey, boolean isReBind) {
        JSONObject jsobj = (JSONObject) message.getTableData(pos, dataKey);
        String titleText = (String) JsonUtil.getValFromJsonObject(jsobj, "t1");
        String contentText = (String) JsonUtil.getValFromJsonObject(jsobj, "t2");
        String titleColor = (String) JsonUtil.getValFromJsonObject(jsobj, "c1");
        String contentColor = (String) JsonUtil.getValFromJsonObject(jsobj, "c2");
        
        
        mTitleView.setText(titleText.trim());
        mContentView.setText(contentText.trim());
        
        ThemeUtil.setTextColor(Constant.getContext(), mTitleView, titleColor, R.color.duoqu_theme_color_5010);
        ThemeUtil.setTextColor(Constant.getContext(), mContentView, contentColor, R.color.duoqu_theme_color_3010);
        
        /* SMARTISAN-313 zhaoxiachao 20161206 start */
        if(pos == 0){
            if(StringUtils.isNull(titleText.trim()) && StringUtils.isNull(contentText.trim() )){
                setVisibility(View.GONE);
            }else{
                setVisibility(View.VISIBLE);
            }
        }
        /* SMARTISAN-313 zhaoxiachao 20161206 end */
    }
    
    public void setVisibility(int visibility) {
        mTitleView.setVisibility(visibility);
        mContentView.setVisibility(visibility);
        if (mContentView.getTag(R.id.tag_parent_layout) != null) {
            ((RelativeLayout) mContentView.getTag(R.id.tag_parent_layout)).setVisibility(visibility);
        }
    }
}